<template>
  <div class="content">
    <div class="tableBox posting_box_list">
      <el-table :data="tableData" stripe style="width: 100%" v-loading="loading" border>
        <template v-for="(item,index) in allData">
          <el-table-column
            :key="index"
            v-if="item.value=='name'"
            :label="item.label"
            align="center"
          >
            <template slot-scope="scope">
              <span
                @click="handleClickNickName(scope.row)"
                style="color: #6b97eb;cursor: pointer;"
              >{{scope.row.name}}</span>
            </template>
          </el-table-column>
          <el-table-column
            :key="index"
            :prop="item.value"
            v-if="item.value!=='opt' && item.value!=='name' && item.value!=='registertime'"
            :label="item.label "
            align="center"
          >
            <!-- <template slot-scope="scope">{{ scope.row.date }}</template> -->
          </el-table-column>
          <el-table-column
            :key="index"
            v-if="item.value=='registertime'"
            :label="item.label"
            min-width="95px"
            align="center"
          >
            <template slot-scope="scope">
              <span>{{scope.row.registertime}}</span>
            </template>
          </el-table-column>
          <el-table-column
            :key="item.value"
            v-else-if="item.value=='opt'"
            label="操作"
            min-width="120px"
            align="center"
          >
            <template slot-scope="scope">
              <el-button @click="lookLog(scope.row)" type="text" size="small">查看日志</el-button>
              <el-button
                @click="handleClickBlacklist(scope.row)"
                type="text"
                v-if="global.powerAllBtn.hygl.hygllhBtn && type== '5'"
              >拉黑</el-button>
              <el-button
                type="text"
                size="small"
                @click="handleClickReport1(scope.row)"
                v-if="global.powerAllBtn.hygl.hyglsbBtn && type== '5'"
              >上报</el-button>
              <el-button
                @click="handleClickRecover(scope.row)"
                type="text"
                v-if="global.powerAllBtn.hygl.hmdhyBtn && type== '6'"
              >还原</el-button>
              <!-- <el-button v-show="scope.row.remark === '1'" type="text" size="small" @click="remove(scope.row)">下架</el-button> -->
              <el-button
                type="text"
                size="small"
                @click="handleClickReport1(scope.row)"
                v-if="global.powerAllBtn.hygl.hmdsbBtn && type== '6'"
              >上报</el-button>
            </template>
          </el-table-column>
        </template>
      </el-table>
    </div>
    <div style="padding:20px 0">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="ScheduleCurrentChange"
        :current-page="pages.pagenum"
        :page-sizes="[10,20, 30, 50,100]"
        :page-size="pages.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pages.total"
        background
      ></el-pagination>
    </div>
    <el-dialog :visible.sync="dialogVisible" width="1040px">
      <resume-detail
        v-if="dialogVisible"
        :userid="userid"
        :nickName="nickName"
        :isShowTelphone="true"
      ></resume-detail>
    </el-dialog>
    <el-dialog :visible.sync="blacklistDialogVisible" width="500px" @close="closeblacklistDialog">
      <div class="warn-dialog-header">
        <span>拉黑操作</span>
      </div>
      <div style="height:40px;display: flex;align-items: center;">
        <el-radio-group v-model="result" style="padding:0 20px" @change="resultChange">
          <el-radio :label="'1'">拉黑</el-radio>
          <el-radio :label="'2'">驳回</el-radio>
        </el-radio-group>
      </div>
      <div class="warn-dialog-body">
        <div v-show="result==='1'">
          <div class="warn-dialog-body-title">拉黑原因</div>
          <el-input type="textarea" :rows="6" v-model.trim="blacklistForm.blackreason"></el-input>
        </div>
        <div class="warn-dialog-btn">
          <el-button style="margin-right: 30px;" @click="blacklistDialogVisible = false">取消</el-button>
          <el-button type="primary" @click="blacklist()">确定</el-button>
        </div>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="warnDialogVisible" width="500px" @close="closeWarnDialog">
      <div class="warn-dialog-header">
        <span>上报原因</span>
      </div>
      <div class="warn-dialog-body">
        <div class="warn-dialog-body-title">发送内容</div>
        <el-input type="textarea" :rows="6" v-model.trim="reportForm.content"></el-input>
        <div class="warn-dialog-btn">
          <el-button style="margin-right: 30px;" @click="warnDialogVisible = false">取消</el-button>
          <el-button type="primary" @click="confirmReport">确定</el-button>
        </div>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="showLog" width="1024px" custom-class="showlog">
      <showLog :reportid="reportId"></showLog>
    </el-dialog>

    <el-dialog :visible.sync="confirmDialogVisible" width="420px" custom-class="confirm" title="提示">
      <span>此操作将还原该用户,是否继续?</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="ignore">移除</el-button>
        <el-button type="primary" @click="toRestore">还原</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import showLog from "../showLog.vue";
import resumeDetail from "../../../component/resumeDetail/index.vue";
export default {
  data () {
    return {
      companyType: '',
      tableData: [],
      loading: false,
      allData: [],
      currentType: '',
      pages: {
        pagesize: 10,
        total: 0,
        pagenum: 1,
      },
      global: {},
      reportId: '',
      result: '1',
      blacklistDialogVisible: false,//拉黑
      blacklistForm: {
        userid: "",
        isblacklist: "",
        blackreason: ""//拉黑原因
      },
      warnDialogVisible: false,//上报弹窗
      reportForm: {
        id: "",
        reporttype: "",
        content: ""
      },
      showLog: false,
      dialogVisible: false,
      nickName: '',
      userid: '',
      confirmDialogVisible: false

    }
  },
  components: {
    showLog,
    resumeDetail
  },
  props: ['type'],
  created () {
    this.allData = [{ label: "会员名称", value: "name" },
    { label: "性别", value: "sex" },
    { label: "出生时期", value: "birthdate" },
    { label: "居住地", value: "address" },
    { label: "手机号码", value: "telnum" },
    { label: "学历", value: "qualification" },
    { label: "求职状态", value: "jobstatus" },
    { label: "注册时间", value: "registertime" },
    { label: "操作", value: "opt" }
    ]
    this.global = this.GLOBAL;
    this.getData();
  },
  methods: {
    //获取列表
    getData () {
      if (!this.type) {
        return;
      }
      this.currentType = this.type;
      this.loading = true;
      this.$axios.post('/app/v1/platform/unusual/todoList', {
        "type": this.type,
        pagesize: this.pages.pagesize,
        pagenum: this.pages.pagenum
      }).then(resp => {
        if (resp.data.message === 'success.') {
          let temp = resp.data.data.list;
          this.tableData = temp || [];
          this.loading = false;
          this.pages.total = Number(resp.data.data.totalnum);
          this.pages.pagesize = Number(resp.data.data.pagesize);

        }
      })
    },
    // 查看会员详情
    handleClickNickName (row) {
      this.userid = row.id;
      this.nickName = row.name;
      this.dialogVisible = true;
    },
    // 拉黑
    handleClickBlacklist (row) {
      this.blacklistForm.userid = row.id;
      this.reportId = row.reportid;
      this.blacklistDialogVisible = true;
    },
    closeblacklistDialog () {
      this.blacklistForm.userid = "";
      this.blacklistForm.isblacklist = "";
      this.blacklistForm.blackreason = "";
    },
    closeWarnDialog () {
      this.reportForm.content = "";
    },

    //还原确定
    toRestore () {
      this.$axios.post("/app/v1/platform/member/joinblacklist", this.blacklistForm).then(res => {
        if (res.data.code === 1) {
          this.$message({
            message: "操作成功",
            type: "success"
          });

          // let currentData = {
          //   reportid: this.reportId,
          //   status: 1,
          //   content: '还原成功'
          // }
          // this.reportCall(currentData)

        } else {
          this.$message({
            message: res.data.message,
            type: "error"
          });
        }
        this.blacklistDialogVisible = false;
        this.confirmDialogVisible = false;
        this.getData();
      });
    },
    //还原忽略=>移除
    ignore () {
      let currentData = {
        reportid: this.reportId,
        status: 2,
        content: "不处理"
      }
      this.reportCall(currentData)
    },


    // 拉黑原因==确定
    blacklist () {
      if (!this.blacklistForm.blackreason && this.result == 1) {
        this.$message({
          message: "请输入拉黑原因",
          type: "warning"
        });
        return
      } else if (this.blacklistForm.blackreason && this.result == 1) {
        this.blacklistForm.isblacklist = "1";
        this.$axios.post("/app/v1/platform/member/joinblacklist", this.blacklistForm).then(res => {
          if (res.data.code === 1) {
            this.$message({
              message: "操作成功",
              type: "success"
            });
            // let data = {
            //   reportid: this.reportId,
            //   status: 1,
            //   content: this.blacklistForm.blackreason || ''
            // }
            // this.reportCallback(data);
          } else {
            this.$message({
              message: res.data.message,
              type: "error"
            });
          }
          this.blacklistDialogVisible = false;
          this.getData();

        });
      } else if (this.result == 2) {
        let currentData = {
          reportid: this.reportId,
          status: 2,
          content: '不同意'
        }
        this.reportCall(currentData)
      }
    },
    //待办==上报
    handleClickReport1 (row) {

      if (this.type == 5) {
        this.reportForm.reporttype = '5';
      } else {
        this.reportForm.reporttype = '6';
      }
      this.reportId = row.reportid;
      this.warnDialogVisible = true;
    },
    //上报里确定
    confirmReport () {
      if (!this.reportForm.content) {
        this.$message({
          type: "warning",
          message: "上报内容不能为空!"
        });
        return;
      }
      let currentData = {
        reportid: this.reportId,
        status: 0,
        content: this.reportForm.content || ''
      }
      this.reportCall(currentData)
    },

    //待办提交
    reportCall (data) {
      this.$axios.post('app/v1/platform/unusual/todoHandleSubmit',
        data
      ).then(resp => {
        if (resp.data.message === 'success.') {
          this.blacklistDialogVisible = false;
          this.warnDialogVisible = false;
          this.confirmDialogVisible = false;
          this.loading = false;
          this.getData();
        } else {
          this.confirmDialogVisible = false;
          this.blacklistDialogVisible = false;
          this.warnDialogVisible = false;
          this.$message({
            message: resp.data.message,
            type: "error"
          });
        }
      })

    },

    resultChange (r) {
      if (r === "2") this.blacklistForm.blackreason = "";
    },

    close () {
      this.checkFlag = false;
      this.getData(this.companyType);
    },
    //分页
    handleSizeChange (val) {
      this.pages.pagenum = 1;
      this.pages.pagesize = val;
      this.getData();
    },

    //分页查询
    ScheduleCurrentChange (val) {
      this.pages.pagenum = val;
      this.getData();
    },

    reportCallback (currentData) {
      var data = {
        reportid: currentData.reportid,
        status: currentData.status,
        content: currentData.content || ''
      }
      this.$emit('reportCallback', data)
    },

    // 还原
    handleClickRecover (row) {
      this.reportId = row.reportid;
      this.blacklistForm.userid = row.id;
      this.blacklistForm.isblacklist = '0';
      this.confirmDialogVisible = true;
      // this.$confirm('此操作将还原该用户, 是否继续?', '提示', {
      //   confirmButtonText: '还原',
      //   cancelButtonText: '移除',
      //   type: 'warning'
      // }).then(() => {
      //   this.blacklistForm.userid = row.id;
      //   this.blacklistForm.isblacklist = '0';
      //   this.$axios.post("/app/v1/platform/member/joinblacklist", this.blacklistForm).then(res => {
      //     if (res.data.code === 1) {
      //       this.$message({
      //         message: "操作成功",
      //         type: "success"
      //       });
      //       this.blacklistDialogVisible = false;
      //       // let currentData = {
      //       //   reportid: this.reportId,
      //       //   status: 1,
      //       //   content: '还原成功'
      //       // }
      //       // this.reportCall(currentData)
      //       this.getData();
      //     } else {
      //       this.$message({
      //         message: res.data.message,
      //         type: "error"
      //       });
      //     }
      //   });
      // }).catch(() => {
      //   let currentData = {
      //     reportid: this.reportId,
      //     status: 2,
      //     content: '不还原操作'
      //   }
      //   this.reportCall(currentData)
      //   console.log("取消操作");
      // });
    },
    lookLog (row) {
      this.reportId = row.reportid;
      this.showLog = true;
    }
  },
  watch: {
    type (newVal, oldVal) {
      this.getData();
    }
  }

}
</script>
<style>
</style>


